﻿using UnityEngine;

namespace UnityX
{
    [DisallowMultipleComponent]
    [AddComponentMenu("Animation/Slide In")]
    public class SlideIn : AnimationBehaviour
    {
        public Vector3 slide = Vector2.zero;
        public AnimationValueType valueType = AnimationValueType.固定增加;

        private Vector3 m_BeginValue;
        private Vector3 m_EndValue;

        protected override void Begin()
        {
            switch (valueType)
            {
                case AnimationValueType.固定值:
                    m_BeginValue = slide;
                    break;
                case AnimationValueType.固定增加:
                    m_BeginValue = transform.localPosition + slide;
                    break;
                case AnimationValueType.倍数:
                    m_BeginValue = transform.localPosition;
                    m_BeginValue = new Vector3(m_BeginValue.x * slide.x, m_BeginValue.y * slide.y, m_BeginValue.z * slide.z);
                    break;
            }
            m_EndValue = transform.localPosition;
            transform.localPosition = m_BeginValue;
        }
        protected override void End()
        {
            transform.localPosition = m_EndValue;
        }
        protected override void Set(float t)
        {
            transform.localPosition = Vector3.Lerp(m_BeginValue, m_EndValue, t);
        }
    }
}